<?php

namespace App\Http\Controllers\Backend;

use App\DataTables\CooperationDataTable;
use App\Http\Requests;
use App\Http\Requests\CreateCooperationRequest;
use App\Http\Requests\UpdateCooperationRequest;
use App\Repositories\CooperationRepository;
use Flash;
use App\Http\Controllers\AppBaseController;
use Response;

class CooperationController extends AppBaseController
{
    /** @var  CooperationRepository */
    private $cooperationRepository;

    public function __construct(CooperationRepository $cooperationRepo)
    {
        $this->cooperationRepository = $cooperationRepo;
    }

    /**
     * Display a listing of the Cooperation.
     *
     * @param CooperationDataTable $cooperationDataTable
     * @return Response
     */
    public function index(CooperationDataTable $cooperationDataTable)
    {
        return $cooperationDataTable->render('backend.cooperations.index');
    }

    /**
     * Show the form for creating a new Cooperation.
     *
     * @return Response
     */
    public function create()
    {
        return view('backend.cooperations.create');
    }

    /**
     * Store a newly created Cooperation in storage.
     *
     * @param CreateCooperationRequest $request
     *
     * @return Response
     */
    public function store(CreateCooperationRequest $request)
    {
        $input = $request->all();

        $cooperation = $this->cooperationRepository->create($input);

        Flash::success(trans('flash.controller.save_success', ['model' => 'Cooperation']));

        return redirect(route('cooperations.index'));
    }

    /**
     * Display the specified Cooperation.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function show($id)
    {
        $cooperation = $this->cooperationRepository->findWithoutFail($id);

        if (empty($cooperation)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Cooperation']));

            return redirect(route('cooperations.index'));
        }

        return view('backend.cooperations.show')->with('cooperation', $cooperation);
    }

    /**
     * Show the form for editing the specified Cooperation.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function edit($id)
    {
        $cooperation = $this->cooperationRepository->findWithoutFail($id);

        if (empty($cooperation)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Cooperation']));

            return redirect(route('cooperations.index'));
        }

        return view('backend.cooperations.edit')->with('cooperation', $cooperation);
    }

    /**
     * Update the specified Cooperation in storage.
     *
     * @param  int              $id
     * @param UpdateCooperationRequest $request
     *
     * @return Response
     */
    public function update($id, UpdateCooperationRequest $request)
    {
        $cooperation = $this->cooperationRepository->findWithoutFail($id);

        if (empty($cooperation)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Cooperation']));

            return redirect(route('cooperations.index'));
        }

        $cooperation = $this->cooperationRepository->update($request->all(), $id);

        Flash::success(trans('flash.controller.update_success', ['model' => 'Cooperation']));

        return redirect(route('cooperations.index'));
    }

    /**
     * Remove the specified Cooperation from storage.
     *
     * @param  int $id
     *
     * @return Response
     */
    public function destroy($id)
    {
        $cooperation = $this->cooperationRepository->findWithoutFail($id);

        if (empty($cooperation)) {
            Flash::error(trans('flash.controller.not_found', ['model' => 'Cooperation']));

            return redirect(route('cooperations.index'));
        }

        $this->cooperationRepository->delete($id);

        Flash::success(trans('flash.controller.delete_success', ['model' => 'Cooperation']));

        return redirect(route('cooperations.index'));
    }
}
